<template>
  <div class="page-common-layout custom-tablePage-container">
    <div class="screen-conditions-container">
      <ScreenConditions :isDataType="false">
        <template slot="conditions">
          <a-input
            style="width: 350px;"
            v-model="condition.name"
            placeholder="请输入交底名称"
          ></a-input>
          <a-input
            style="width: 350px;"
            v-model="condition.location"
            placeholder="请输入地点"
          ></a-input>
          <a-select placeholder="请选择专业" v-model="condition.major">
            <a-select-option
              :value="item.dicItemCode"
              v-for="item in majorSource"
              :key="item.dicItemCode"
            >
              {{ item.dicItemName }}
            </a-select-option>
          </a-select>
          <a-range-picker
            format="YYYY-MM-DD"
            valueFormat="YYYY-MM-DD"
            v-model="condition.date"
            :show-time="false"
          />

          <a-input
            style="width: 350px;"
            v-model="condition.creator"
            placeholder="请输入提交人"
          ></a-input>
          <a-range-picker
            format="YYYY-MM-DD"
            valueFormat="YYYY-MM-DD"
            v-model="condition.createTime"
            :show-time="false"
            :placeholder="['提交开始日期', '提交结束日期']"
          />
          <a-select placeholder="请选择状态" v-model="condition.approveStatus">
            <a-select-option value="0">
              待提交
            </a-select-option>
            <a-select-option value="1">
              审批中
            </a-select-option>
            <a-select-option value="2">
              审批完成
            </a-select-option>
            <a-select-option value="3">
              驳回
            </a-select-option>
          </a-select>
        </template>
        <template slot="operate">
          <a-button class="cu-btn-primary" icon="search" @click="search()">
            查询
          </a-button>
          <a-button class="cu-btn-filter" icon="reload" @click="reset()">
            重置
          </a-button>
        </template>
      </ScreenConditions>
    </div>
    <div class="table-body-container">
      <div class="table-operate">
        <a-button
          @click="handleWrapPage({}, 1)"
          class="cu-btn-primary margin-bottom-xs"
          icon="plus"
          v-action="'sjjd_table_add'"
        >
          新增
        </a-button>
      </div>
      <div class="table-main">
        <vxe-table
          ref="xTable"
          height="99%"
          align="left"
          show-overflow
          show-header-overflow
          border="inner"
          :data="tableData"
          :column-config="{ resizable: true }"
          size="small"
          :loading="loading"
          :row-config="{ keyField: 'uuid' }"
          :expand-config="{
            reserve: true,
            visibleMethod: visibleMethod,
          }"
        >
          <vxe-column type="expand" width="26">
            <template #content="{ row }">
              <div class="expand-wrapper">
                <vxe-table
                  align="center"
                  border="inner"
                  :data="row.historys || []"
                  :column-config="{ resizable: true }"
                  show-overflow
                  show-header-overflow
                  size="small"
                >
                  <vxe-column field="versionNumber" title="版本号">
                  </vxe-column>
                  <vxe-column field="name" title="交底名称"> </vxe-column>
                  <vxe-column field="time" title="时间"> </vxe-column>
                  <vxe-column field="location" title="地点"> </vxe-column>
                  <vxe-column field="majorDesc" title="专业"> </vxe-column>
                  <vxe-column title="设计院交底文件">
                    <template #default="{ row,rowIndex }">
                      <div class="files-icon">
                        <!-- 预览 -->
                        <a-tooltip placement="top">
                          <template slot="title">
                            预览
                          </template>
                          <a-icon
                            type="eye"
                            :class="[
                              isEmptyObject(row.fileIdInfo) && 'disabled',
                            ]"
                            @click="
                              previewFile(row.fileIdInfo, '设计院交底文件', row)
                            "
                          />
                        </a-tooltip>
                        <!-- 下载 -->
                        <a-tooltip placement="top" v-action:sjjd_table_download>
                          <template slot="title">
                            下载
                          </template>
                          <a-icon
                            v-if="
                              row['fileIdInfo']
                                ? row['fileIdInfo'].downloadStatus
                                : false
                            "
                            type="sync"
                            spin
                          />
                          <a-icon
                            v-else
                            type="download"
                            :class="[
                              isEmptyObject(row.fileIdInfo) && 'disabled',
                            ]"
                            @click="
                              downloadFile(
                                row.fileIdInfo,
                                '设计院交底文件',
                                row,
                                rowIndex,
                                'fileIdInfo'
                              )
                            "
                          />
                        </a-tooltip>
                      </div>
                    </template>
                  </vxe-column>
                  <vxe-column title="交底记录">
                    <template #default="{ row,rowIndex }">
                      <div class="files-icon">
                        <!-- 预览 -->
                        <a-tooltip placement="top">
                          <template slot="title">
                            预览
                          </template>
                          <a-icon
                            type="eye"
                            :class="[
                              isEmptyObject(row.disclosureRecord) && 'disabled',
                            ]"
                            @click="
                              previewFile(row.disclosureRecord, '交底记录', row)
                            "
                          />
                        </a-tooltip>
                        <!-- 下载 -->
                        <a-tooltip placement="top" v-action:sjjd_table_download>
                          <template slot="title">
                            下载
                          </template>
                          <a-icon
                            v-if="
                              row['disclosureRecord']
                                ? row['disclosureRecord'].downloadStatus
                                : false
                            "
                            type="sync"
                            spin
                          />
                          <a-icon
                            v-else
                            type="download"
                            :class="[
                              isEmptyObject(row.disclosureRecord) && 'disabled',
                            ]"
                            @click="
                              downloadFile(
                                row.disclosureRecord,
                                '交底记录',
                                row,
                                rowIndex,
                                'disclosureRecord'
                              )
                            "
                          />
                        </a-tooltip>
                      </div>
                    </template>
                  </vxe-column>
                  <vxe-column title="其他文件">
                    <template #default="{ row,rowIndex }">
                      <div class="files-icon">
                        <!-- 预览 -->
                        <a-tooltip placement="top">
                          <template slot="title">
                            预览
                          </template>
                          <a-icon
                            type="eye"
                            :class="[
                              isEmptyObject(row.otherDocuments) && 'disabled',
                            ]"
                            @click="
                              previewFile(row.otherDocuments, '其他文件', row)
                            "
                          />
                        </a-tooltip>
                        <!-- 下载 -->
                        <a-tooltip placement="top" v-action:sjjd_table_download>
                          <template slot="title">
                            下载
                          </template>
                          <a-icon
                            v-if="
                              row['otherDocuments']
                                ? row['otherDocuments'].downloadStatus
                                : false
                            "
                            type="sync"
                            spin
                          />
                          <a-icon
                            type="download"
                            v-else
                            :class="[
                              isEmptyObject(row.otherDocuments) && 'disabled',
                            ]"
                            @click="
                              downloadFile(
                                row.otherDocuments,
                                '其他文件',
                                row,
                                rowIndex,
                                'otherDocuments'
                              )
                            "
                          />
                        </a-tooltip>
                      </div>
                    </template>
                  </vxe-column>
                  <vxe-column field="reason" title="驳回原因"> </vxe-column>
                  <vxe-column
                    field="operate"
                    width="60"
                    title="操作"
                    fixed="right"
                  >
                    <template #default="{ row }">
                      <div class="text-button-group">
                        <a-tooltip placement="top">
                          <template slot="title">
                            查看
                          </template>
                          <a-icon
                            type="file-search"
                            @click="handleDetailPage(row, 1)"
                          />
                        </a-tooltip>
                      </div>
                    </template>
                  </vxe-column>
                </vxe-table>
              </div>
            </template>
          </vxe-column>
          <vxe-column
            type="seq"
            width="50"
            title="序号"
            align="center"
          ></vxe-column>
          <vxe-column field="name" title="交底名称"> </vxe-column>
          <vxe-column field="time" title="时间"> </vxe-column>
          <vxe-column field="location" title="地点"> </vxe-column>
          <vxe-column field="majorDesc" title="专业"> </vxe-column>
          <vxe-column title="设计院交底文件">
            <template #default="{ row,rowIndex }">
              <div class="files-icon">
                <!-- 预览 -->
                <a-tooltip placement="top">
                  <template slot="title">
                    预览
                  </template>
                  <a-icon
                    type="eye"
                    :class="[isEmptyObject(row.fileIdInfo) && 'disabled']"
                    @click="previewFile(row.fileIdInfo, '设计院交底文件', row)"
                  />
                </a-tooltip>
                <!-- 下载 -->
                <a-tooltip placement="top" v-action:sjjd_table_download>
                  <template slot="title">
                    下载
                  </template>
                  <a-icon
                    v-if="
                      row['fileIdInfo']
                        ? row['fileIdInfo'].downloadStatus
                        : false
                    "
                    type="sync"
                    spin
                  />
                  <a-icon
                    v-else
                    type="download"
                    :class="[isEmptyObject(row.fileIdInfo) && 'disabled']"
                    @click="
                      downloadFile(
                        row.fileIdInfo,
                        '设计院交底文件',
                        row,
                        rowIndex,
                        'fileIdInfo'
                      )
                    "
                  />
                </a-tooltip>
              </div>
            </template>
          </vxe-column>
          <vxe-column title="交底记录">
            <template #default="{ row,rowIndex }">
              <div class="files-icon">
                <!-- 预览 -->
                <a-tooltip placement="top">
                  <template slot="title">
                    预览
                  </template>
                  <a-icon
                    type="eye"
                    :class="[isEmptyObject(row.disclosureRecord) && 'disabled']"
                    @click="previewFile(row.disclosureRecord, '交底记录', row)"
                  />
                </a-tooltip>
                <!-- 下载 -->
                <a-tooltip placement="top" v-action:sjjd_table_download>
                  <template slot="title">
                    下载
                  </template>
                  <a-icon
                    v-if="
                      row['fileIdInfo']
                        ? row['fileIdInfo'].downloadStatus
                        : false
                    "
                    type="sync"
                    spin
                  />
                  <a-icon
                    v-else
                    type="download"
                    :class="[isEmptyObject(row.disclosureRecord) && 'disabled']"
                    @click="
                      downloadFile(
                        row.disclosureRecord,
                        '交底记录',
                        row,
                        rowIndex,
                        'disclosureRecord'
                      )
                    "
                  />
                </a-tooltip>
              </div>
            </template>
          </vxe-column>
          <vxe-column title="其他文件">
            <template #default="{ row,rowIndex }">
              <div class="files-icon">
                <!-- 预览 -->
                <a-tooltip placement="top">
                  <template slot="title">
                    预览
                  </template>
                  <a-icon
                    type="eye"
                    :class="[isEmptyObject(row.otherDocuments) && 'disabled']"
                    @click="previewFile(row.otherDocuments, '其他文件', row)"
                  />
                </a-tooltip>
                <!-- 下载 -->
                <a-tooltip placement="top" v-action:sjjd_table_download>
                  <template slot="title">
                    下载
                  </template>
                  <a-icon
                    v-if="
                      row['fileIdInfo']
                        ? row['fileIdInfo'].downloadStatus
                        : false
                    "
                    type="sync"
                    spin
                  />
                  <a-icon
                    type="download"
                    v-else
                    :class="[isEmptyObject(row.otherDocuments) && 'disabled']"
                    @click="
                      downloadFile(
                        row.otherDocuments,
                        '其他文件',
                        row,
                        rowIndex,
                        'otherDocuments'
                      )
                    "
                  />
                </a-tooltip>
              </div>
            </template>
          </vxe-column>
          <vxe-column title="状态" width="100">
            <template #default="{ row }">
              <div class="state" :class="[filterStateClass(row.approveStatus)]">
                {{ filterStateName(row.approveStatus) }}
              </div>
            </template>
          </vxe-column>
          <vxe-column
            field="operate"
            width="180"
            title="操作"
            fixed="right"
            align="left"
          >
            <template #default="{ row }">
              <div class="text-button-group">
                <a-tooltip placement="top">
                  <template slot="title">
                    查看
                  </template>
                  <a-icon
                    type="file-search"
                    @click="handleDetailPage(row, 1)"
                  />
                </a-tooltip>
                <a-tooltip placement="top" v-if="row.approveRecord">
                  <template slot="title">
                    审批记录
                  </template>
                  <icon-fonts
                    icon="icon-shenpi"
                    class="record"
                    @change="gotoApprovalRecord(row)"
                  ></icon-fonts>
                </a-tooltip>

                <a-tooltip
                  placement="top"
                  v-if="row.submit"
                  v-action="'sjjd_table_submit'"
                >
                  <template slot="title">
                    提交
                  </template>
                  <icon-fonts
                    icon="icon-fabu-tijiao-tijiaobanben"
                    class="submit"
                    @change="handleSubmit(row)"
                  ></icon-fonts>
                </a-tooltip>

                <a-tooltip placement="top" v-if="row.approve">
                  <template slot="title">
                    审批
                  </template>
                  <icon-fonts
                    icon="icon-shenpi1"
                    class="approve"
                    @change="handleDetailPage(row, 2)"
                  ></icon-fonts>
                </a-tooltip>

                <a-tooltip v-action="'sjjd_table_edit'" v-if="row.edit">
                  <template slot="title">
                    编辑
                  </template>
                  <a-icon type="edit" @click="handleWrapPage(row, 2)" />
                </a-tooltip>

                <a-tooltip v-action="'sjjd_table_del'" v-if="row.del">
                  <template slot="title">
                    删除
                  </template>
                  <a-icon type="delete" @click="handleDelClick(row)" />
                </a-tooltip>
              </div>
            </template>
          </vxe-column>
        </vxe-table>
      </div>
      <div class="table-pager">
        <vxe-pager
          size="small"
          background
          :current-page.sync="pager.page"
          :page-size.sync="pager.pageSize"
          :total="pager.total"
          :layouts="['PrevPage', 'JumpNumber', 'NextPage', 'Sizes']"
          :page-sizes="[20, 50, 100, 500]"
          @page-change="paginationChange"
        >
          <template #left>
            <div class="vxe-pager-left-tip-container">
              共<span>{{ pager.total }}</span
              >条
            </div>
          </template>
        </vxe-pager>
      </div>
    </div>
    <!-- 新增/编辑/查看 -->
    <wrapPage
      :key="wrapPage.key"
      :visible.sync="wrapPage.visible"
      :parameter="wrapPage.row"
      :pageOperate="wrapPage.operate"
    ></wrapPage>
    <!-- 查看附件 -->
    <viewFileModal
      :visible.sync="viewFileModal.visible"
      :fileList="viewFileModal.fileList"
      :subtitle="viewFileModal.name"
    ></viewFileModal>

    <!-- 审批记录 -->
    <comment-modal ref="commentModal"></comment-modal>

    <!-- 详情 -->
    <detailPage
      :key="detailPage.key"
      :visible.sync="detailPage.visible"
      :parameter="detailPage.row"
      :pageOperate="detailPage.operate"
    ></detailPage>

    <!--  目录+文件预览 -->
    <treeViewFileModal
      :visible.sync="treeViewFileModal.visible"
      :subtitle="treeViewFileModal.name"
      :dataSource="treeViewFileModal.source"
    ></treeViewFileModal>

    <!-- 单文件预览弹窗 -->
    <previewModal
      ref="previewModal"
      :visible.sync="previewModal.visible"
      :loading="previewModal.loading"
    ></previewModal>
  </div>
</template>

<script>
// 设计交底
import { mapGetters } from "vuex";
import moment from "moment";
import { _getUUID } from "@/utils/util.js";
import { downLoadBatchFileByArraybuffer, getToken } from "@/utils/TopVUI";
import ScreenConditions from "@/components/extendCustom/ScreenConditions";
import wrapPage from "./wrapPage.vue";
//预览
import viewFileModal from "./viewFileModal";
//审批记录
import commentModal from "@/pages/workflow/oaLeave/comment.vue";
//详情
import detailPage from "./detailPage.vue";
//目录+文件预览
import treeViewFileModal from "./treeViewFileModal.vue";
//单文件预览
import previewModal from "@/pages/document/minio/previewModal";
import { getDicItemByCode } from "@/api/common";
import {
  pageDesignBriefing,
  deleteDesignBriefing,
  zipDesignBriefing,
  submitDesignBriefing,
  exportZip67,
} from "@/api/design";
export default {
  components: {
    ScreenConditions,
    wrapPage,
    viewFileModal,
    commentModal,
    detailPage,
    treeViewFileModal,
    previewModal,
  },
  data() {
    return {
      //查询条件
      condition: {
        //交底名称
        name: "",
        //日期范围
        date: [],
        //专业
        major: undefined,
        //地点
        location: "",
        //提交时间
        createTime: [],
        //提交人
        creator: "",
        //状态
        approveStatus: undefined,
      },
      //专业
      majorSource: [],
      //列表
      loading: false,
      tableData: [],
      pager: {
        page: 1,
        pageSize: 50,
        total: 0,
      },
      // 新增/编辑/查看
      wrapPage: {
        visible: false,
        key: _getUUID(),
        row: {},
        operate: 1,
      },
      //查看附件
      viewFileModal: {
        classifyId: "",
        name: "",
        visible: false,
        fileList: [],
      },
      //详情 1详情2审批
      detailPage: {
        visible: false,
        key: _getUUID(),
        row: {},
        operate: 1,
      },
      //目录+文件预览
      treeViewFileModal: {
        visible: false,
        name: "",
        source: {},
      },
      //单文件预览
      previewModal: {
        visible: false,
        loading: false,
      },
    };
  },
  computed: {
    ...mapGetters(["configData", "userInfo"]),
    kkFileView() {
      let index = this.configData.findIndex(
        (item) => item.code === "kkFileView"
      );
      if (index >= 0) {
        return this.configData[index].value;
      } else {
        return "http://192.168.1.216:8012/onlinePreview";
      }
    },
  },
  mounted() {
    this.getData();
  },
  methods: {
    moment,
    //是否是空对象
    isEmptyObject(obj = {}) {
      if (Object.keys(obj).length == 0) {
        return true;
      } else if ((obj?.fileIdInfo || []).length == 0) {
        return true;
      } else {
        return false;
      }
    },
    async getData() {
      //专业
      this.majorSource = await this.getDicCodeData("major");
      await this.getTableData();
    },
    //查询字典表
    getDicCodeData(dicCode = "") {
      return new Promise((resolve, reject) => {
        getDicItemByCode({ code: dicCode })
          .then((res) => {
            let { data } = res;
            resolve(data);
          })
          .catch((_) => {
            reject();
          })
          .finally((_) => {});
      });
    },

    // 新增/编辑
    handleWrapPage(row, operate) {
      this.wrapPage.operate = operate;
      this.wrapPage.row = row;
      this.wrapPage.key = _getUUID();
      this.wrapPage.visible = true;
    },
    //详情、审批
    handleDetailPage(row, operate) {
      this.detailPage.operate = operate;
      this.detailPage.row = row;
      this.detailPage.key = _getUUID();
      this.detailPage.visible = true;
    },

    //预览
    previewFile(files, name, record) {
      let { fileIdInfo = [], classifyId } = files;
      if (fileIdInfo.length == 0) {
        return;
      } else if (fileIdInfo.length == 1) {
        let fileItem = fileIdInfo?.[0] ?? {};
        this.viewFile(fileItem);
      } else {
        if (classifyId) {
          this.treeViewFileModal.name = name;
          this.treeViewFileModal.source = {
            classifyId,
            uuid: record.uuid,
          };
          this.treeViewFileModal.visible = true;
        } else {
          this.viewFileModal.name = name;
          this.viewFileModal.fileList = fileIdInfo ?? [];
          this.viewFileModal.visible = true;
        }
      }
    },

    //预览
    viewFile(file) {
      let { previewWay, fileName, url, uuid, unit, bimCadFile } = file;
      let domain = location.origin;
      switch (previewWay) {
        //cad预览
        case "cad":
          window.open(
            `${domain}/#/blackHole/previewCad?uuid=${uuid}&fileName=${fileName}&unit=${unit}`
          );
          return;
        // 模型预览
        case "model":
          let { bhDataSetId } = bimCadFile || {};
          bhDataSetId &&
            window.open(
              `${domain}/#/blackHole/viewDataSetSingleSimple?dataSetId=${bhDataSetId}&name=${fileName}`
            );
          return;
        // 普通文件预览
        default:
          this.previewModal.loading = true;
          this.$refs.previewModal.type = "file";
          this.$refs.previewModal.fileUrl =
            this.kkFileView +
            "/onlinePreview?url=" +
            encodeURIComponent(Base64.encode(url)) +
            "&watermarkTxt=" +
            //水印内容
            encodeURIComponent("") +
            "&token=" +
            getToken();
          this.previewModal.visible = true;
          this.previewModal.loading = false;
          break;
      }
    },

    //审批记录
    gotoApprovalRecord(record) {
      this.$refs.commentModal.getCommentList(record.uuid);
    },

    //下载
    downloadFile(files, name, row = {}, rowIndex, key) {
      let { classifyId, fileIdInfo = [] } = files;
      let { uuid } = row;
      if (fileIdInfo.length == 0) {
        return;
      }
      this.tableData[rowIndex][key].downloadStatus = true;
      if (name == "设计院交底文件") {
        exportZip67({ uuid, classifyId: classifyId, type: 6 })
          .then((data) => {
            downLoadBatchFileByArraybuffer(data, name);
          })
          .catch((_) => {})
          .finally((_) => {
            this.tableData[rowIndex][key].downloadStatus = false;
          });
      } else {
        let ids = fileIdInfo.map((v) => v.dfsFileUuid);
        zipDesignBriefing({ fileIds: ids.toString() })
          .then((data) => {
            downLoadBatchFileByArraybuffer(data, name);
          })
          .catch((_) => {})
          .finally((_) => {
            this.tableData[rowIndex].fileIdInfo.downloadStatus = false;
          });
      }

      return;
    },

    //删除
    handleDelClick(row) {
      let dataLength = this.tableData.length;
      let that = this;
      that.$confirm({
        title: "提示",
        content: "确定删除该数据吗？删除之后不可恢复！",
        okText: "确定",
        cancelText: "取消",
        icon: () =>
          that.$createElement("a-icon", {
            props: {
              key: "warning",
              type: "exclamation-circle",
              twoToneColor: "#faad14",
            },
          }),
        onOk() {
          deleteDesignBriefing({ uuid: row.uuid })
            .then((res) => {
              if (res.statusCode === 200 || res === 1) {
                that.$message.success("删除成功", 1.5);
                if (dataLength == 1 && that.pager.page > 1) {
                  that.pager.page -= 1;
                }
                that.getTableData();
              } else {
                that.$message.error(res.message);
              }
            })
            .catch((_) => {});
        },
      });
    },

    //提交
    handleSubmit(row) {
      let that = this;
      let { uuid } = row;
      const h = this.$createElement;
      this.$confirm({
        title: "您确定提交所选内容?",
        content: "",
        okText: "确定",
        okType: "primary",
        cancelText: "取消",
        centered: true,
        icon: () =>
          h("a-icon", {
            props: {
              type: "question-circle",
              theme: "filled",
            },
            style: "color:#FAAD14",
          }),
        onOk() {
          that.loading = true;
          submitDesignBriefing({ uuid })
            .then((res) => {
              if (res.statusCode === 200 || res === 1) {
                that.$message.success("提交成功", 1.5);
                that.getTableData();
              } else {
                that.$message.error(res?.message ?? "提交失败");
              }
            })
            .catch((_) => {
              that.$message.error(res?.message ?? "提交失败");
            })
            .finally(() => {
              that.loading = false;
            });
        },
        onCancel() {},
      });
    },

    //查询
    search() {
      this.pager.page = 1;
      this.getTableData();
    },

    //重置
    reset() {
      this.condition = {
        //交底名称
        name: "",
        //日期范围
        date: [],
        //专业
        major: undefined,
        //地点
        location: "",
        //提交时间
        createTime: [],
        //提交人
        creator: "",
        //状态
        approveStatus: undefined,
      };
      this.search();
    },

    visibleMethod({ row }) {
      if (row.historys && row.historys.length != 0) {
        return true;
      } else {
        return false;
      }
    },
    //查询列表数据
    getTableData() {
      this.loading = true;
      let { page, pageSize } = this.pager;
      let {
        name,
        date,
        major = "",
        createTime,
        creator,
        location,
        approveStatus = "",
      } = this.condition;
      return new Promise((resolve, reject) => {
        pageDesignBriefing({
          page,
          pageSize,
          name,
          major,
          startTime: date?.[0] ?? "",
          endTime: date?.[1] ?? "",
          startTimeSub: createTime?.[0] ?? "",
          endTimeSub: createTime?.[1] ?? "",
          creator,
          location,
          approveStatus,
        })
          .then((res) => {
            this.tableData = res.data?.rows || [];
            this.pager.total = res.data?.totalCount || 0;
            let codes = ["disclosureRecord", "otherDocuments"];
            this.tableData.forEach((item) => {
              if (!item.fileIdInfo) {
                item.fileIdInfo = {
                  downloadStatus: false,
                  fileIdInfo: [],
                };
              }
              if (!item.disclosureRecord) {
                item.disclosureRecord = {
                  downloadStatus: false,
                  fileIdInfo: [],
                };
              }
              if (!item.otherDocuments) {
                item.otherDocuments = {
                  downloadStatus: false,
                  fileIdInfo: [],
                };
              }
              for (let key in item) {
                if (codes.includes(key)) {
                  item[key] = JSON.parse(item[key] ?? "{}");
                }
              }
              item.historys.forEach((v) => {
                if (!v.fileIdInfo) {
                  v.fileIdInfo = {
                    downloadStatus: false,
                    fileIdInfo: [],
                  };
                }
                if (!v.disclosureRecord) {
                  v.disclosureRecord = {
                    downloadStatus: false,
                    fileIdInfo: [],
                  };
                }
                if (!v.otherDocuments) {
                  v.otherDocuments = {
                    downloadStatus: false,
                    fileIdInfo: [],
                  };
                }
                for (let key in v) {
                  if (codes.includes(key)) {
                    v[key] = JSON.parse(v[key] ?? "{}");
                  }
                }
              });
            });
            resolve();
          })
          .catch((_) => {
            this.tableData = [];
            this.pager.total = 0;
            reject();
          })
          .finally((_) => {
            this.loading = false;
          });
      });
    },

    //监听分页切换
    paginationChange({ currentPage, pageSize }) {
      this.pager.page = currentPage;
      this.pager.pageSize = pageSize;
      this.getTableData();
    },

    filterStateName(val) {
      switch (val) {
        case 0:
          return "待提交";
        case 1:
          return "审批中";
        case 2:
          return "审批通过";
        case 3:
          return "驳回";
        default:
          return "-";
      }
    },

    filterStateClass(val) {
      switch (val) {
        case 0:
          return "default";
        case 1:
          return "ing";
        case 2:
          return "lock";
        case 3:
          return "error";
        default:
          return "";
      }
    },

    //select 搜索过滤
    filterOption(input, option) {
      return (
        option.componentOptions.children[0].text
          .toLowerCase()
          .indexOf(input.toLowerCase()) >= 0
      );
    },
  },
};
</script>

<style lang="scss" scoped>
.screen-conditions-container {
  .more {
    cursor: pointer;
    font-size: 14px;
    color: #1890ff;
    margin-left: 10px;
    padding-top: 6px;
    .anticon {
      font-size: 12px;
    }
  }
}
.expand-wrapper {
  padding: 10px;
  box-sizing: border-box;
}
.state {
  &::before {
    position: relative;
    display: inline-block;
    content: "";
    width: 8px;
    height: 8px;
    background: #239b53;
    border-radius: 0px 0px 0px 0px;
    border-radius: 50%;
    margin-right: 10px;
  }
  &.default {
    &::before {
      background: #8c8c8c;
    }
  }
  &.ing {
    &::before {
      background: #f07f17;
    }
  }
  &.lock {
    &::before {
      background: #239b53;
    }
  }

  &.error {
    &::before {
      background: #ff3f4a;
    }
  }
}
</style>
